/**
 * Created by AllanXu on 7/25/2016.
 */
define(function (require) {
    var Vue = require('vue'),
        Config = require('config'),
        _ = require('ajax'),
        utilities = require('utilities');

    var id = utilities.getParameterByName('id');

    var app = new Vue({
        el: '#enroll_list',
        data: {
            pageCount: '',
            pageno: 1,
            renderObj: {
                listArr: []
            },
            keywords:'',
            tabsName: [],
            typeId: '',
            curNum: -1,
            bottomTxt: '',
            // 筛选
            filter: false,
            filterArr: '',
            ageArr: [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45],
            sex: '',
            ageMin: '',
            ageMax: '',
            marriage: '',
            // 接口参数使用
            selectedAgeMin: '',
            selectedAgeMax: '',

            educations: '',
            income: '',
            // 地区
            cityArr: [],
            countyArr: '',
            // 挑选的市县id
            selectedCityId: '',
            selectedCountyId: '',
            region: '',

            // 打招呼
            msgPageno: 1,
            msgDialog: false,
            msgPageCount: '',
            msgList: [],
            selectMsgIndex: -1,
            selectMsg: '',
            mateId: '',
            // 发信息
            showSendMsg: false,
            msgContent: '',
            picServer: Config.picServer,
            defaultAdd: '江西省'
        },
        methods: {
            init: function () {
                _(Config.SERVICE.ACTIVITY.ENROLLAPPLIEDS+'?blind.id='+id+'&pageno='+app.pageno+'&pagesize=10', {}, function (data) {
                        if (app.pageno == 1) {
                            app.renderObj.listArr = data.pageitems;
                            app.pageCount = data.pagecount;
                        } else {
                            app.renderObj.listArr = app.renderObj.listArr.concat(data.pageitems);
                        }
                    }
                );
            },
            search:function(){
                if(app.keywords==''){
                    alert("请输入会员ID");
                    return;
                }
                if(isNaN(app.keywords)){
                    alert("输入的会员ID格式有误");
                    return;
                }
                _(Config.SERVICE.ACTIVITY.ENROLLAPPLIEDS+'?blind.id='+id+'&pageno='+app.pageno+'&pagesize=10'+'&id='+app.keywords, {}, function (data) {
                        if (app.pageno == 1) {
                            app.renderObj.listArr = data.pageitems;
                            app.pageCount = data.pagecount;
                        } else {
                            app.renderObj.listArr = app.renderObj.listArr.concat(data.pageitems);
                        }
                    }
                );
            },
            goDetail: function (id) {
                location.href = 'enroll_detail.html?id=' + id;
            }
        }
    });
    app.init();

    window.onscroll = function () {
        var scrolltop = document.body.scrollTop | document.documentElement.scrollTop;
        var clientHeight = document.documentElement.clientHeight;
        if (scrolltop + clientHeight == document.body.clientHeight) {
            if (app.pageno <= app.pageCount) {
                app.pageno++;
                app.init();
            } else {
                app.bottomTxt = '到底儿了~';
            }
        }
    }
});